/**
 * \* Created with IntelliJ IDEA.
 * \* User: Administrator
 * \* Date: 2021/12/21
 * \* Time: 10:39
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */
class MyArrayList<E>{
    private E[]elem;
    private int usedSize;

    public MyArrayList(){
        //this.elem=new E[10];//泛型不能实例化对象
        this.elem=(E[]) new Object[10];
    }

    public void add(E val){
        this.elem[usedSize]=val;
        usedSize++;
    }
    public E get(int pos){
        return this.elem[pos];
    }
}
public class TestDemo {

    public static void main(String[] args) {
        System.out.println(Integer.valueOf(1) ==Integer.valueOf(1)); //true
        System.out.println(Integer.valueOf(999) ==Integer.valueOf(999)); //false
    }

    public static void main2(String[] args) {
        MyArrayList<String> myArrayList1=new MyArrayList<>();
        myArrayList1.add("adg");
        String ret=myArrayList1.get(1);//自动进行强制类型转换
        System.out.println(ret);

        MyArrayList<Integer> myArrayList2=new MyArrayList<>();
        myArrayList2.add(1);
        myArrayList2.add(3);
        int ret2=myArrayList2.get(1);
        System.out.println(ret2);
    }

    public static void main1(String[] args) {
        MyArrayList myArrayList=new MyArrayList();
        myArrayList.add(1);
        myArrayList.add("aaa");
        String ret=(String) myArrayList.get(1);
    }
}
